package com.example.meterialproject.activitys

import android.os.Bundle
import android.widget.ArrayAdapter
import androidx.core.widget.doOnTextChanged
import com.example.meterialproject.base.BaseActivity
import com.example.meterialproject.R
import com.example.meterialproject.databinding.ActivityMaterialEditBinding
import com.example.meterialproject.exts.showSnack

/**
 *
 * @ClassName: editActivity
 * @Author: android 超级兵
 * @CreateDate: 1/19/22$ 3:36 PM$
 * TODO materialEdit
 *      AutoCompleteTextView
 * 参考:https://material.io/components/text-fields/android#using-text-fields
 */
class EditActivity : BaseActivity<ActivityMaterialEditBinding>() {


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        // 点击监听
        binding.endEditField.setEndIconOnClickListener {
            it.showSnack(binding.endEditField.editText?.text)
        }


        binding.errorTextInput.addOnEditTextAttachedListener {
        }








        binding.errorEditText.doOnTextChanged { text, start, count, after ->
            if (text?.length!! >= 11) {
                binding.errorTextInput.error = "动态代码设置.错误信息"
                binding.errorEditText.error = "只能输入11位"
//                binding.errorTextInput.errorIconDrawable =
//                    resources.getDrawable(R.drawable.ic_emoji_05)
            } else {
                binding.errorTextInput.error = null
            }
            binding.errorTextInput.errorIconDrawable = null
        }


        binding.errorTextInput.setErrorIconOnClickListener {
            it.showSnack("只能输入11位。。。")
            binding.errorEditText.error = "只能输入11位"
        }


        val items =
            listOf(
                "Material",
                "Design",
                "Components",
                "Android",
                "kotlin",
                "java",
                "ios",
                "c",
                "c++",
                "js",
                "python"
            )
        val adapter = ArrayAdapter(this, R.layout.list_item, items)
        binding.autoText.setAdapter(adapter)

        // 设置AutoCompleteTextView.pop背景
        binding.autoText.setDropDownBackgroundResource(R.drawable.ic_emoji_06)

    }
}